<?php


namespace App\Models;


use Illuminate\Database\Eloquent\Model;

class Users extends Model
{

    public $timestamps = false;

    public static function getByMobile($mobile, $admin = 0){
        $model = self::query()->where("mobile", $mobile);
        if($admin) {
            $model = $model->where('admin', 1);
        }
        return $model->first();
    }

    public static function getByToken($token){
        return self::query()->where("token", $token)->first();
    }


    public static function getRewardRate($achievement, $isAgent, $rewardRate){
        if($rewardRate > 0) {
            return $rewardRate;
        }
        if(!$isAgent) {
            return 0;
        }
        $map = [
            10000 => 0.09,
            20000 => 0.10,
            30000 => 0.11,
            40000 => 0.12,
            50000 => 0.13,
            60000 => 0.14,
            70000 => 0.15,
        ];
        foreach ($map as $k => $v) {
            if($achievement < $k) {
                return $v;
            }
        }
        return 0.15;
    }

}
